home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000103_icon-group-sender_Tue Oct 24 16:47:52 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9ONlh625768
  4.     for icon-group-addresses; Tue, 24 Oct 2000 16:47:44 -0700 (MST)
  5. Message-Id: <200010242347.e9ONlh625768@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 24 Oct 2000 16:10:26 -0500
  7. From: "Charles Hethcoat" <CHETHCOA@oss.oceaneering.com>
  8. To: <icon-group@cs.arizona.edu>
  9. Subject: Re: How to "declare" a string?
  10. Content-Disposition: inline
  11. X-Guinevere: 1.0.13 ; Oceaneering Int'l
  12. X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id e9OLA0325855
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: RO
  15. Content-Length: 1418
  16.  
  17. >>> <symbiot@my-deja.com> 00-10-24 1:03:48 PM >>> wrote:
  18.  
  19. > So again I'm back to the quesiton, "How to 'declare' a string variable?"
  20.  
  21. I don't know if this will help answer the question, which I am admittedly quite confused about.  However, a few smart tests can take you far.  Try this:
  22.  
  23. procedure main()
  24.     s1 := "This is a string"
  25.     write(s1)
  26. #    s2[2] := s1
  27. #    write(s2)
  28.     s3 := "Oh, no, Mr. Bill!  "
  29.     s4 := s3 || s1
  30.     write(s4)
  31.     s3[2] := s1
  32.     write(s3)
  33.     exit()
  34. end
  35.  
  36. You get:
  37.  
  38. This is a string
  39. Oh, no, Mr. Bill!  This is a string
  40. OThis is a string, no, Mr. Bill!  
  41.  
  42. Now remove the comments and watch it die.  Why?  I'm not a guru on the innards of Icon parsing, but my guess is that the line
  43.  
  44. s2[2] := s1
  45.  
  46. is ambiguous.  s2 could be a string OR a table.  Either one would be syntactically correct.  So what's a parser to do?  Later on, s3 is already a string, so there is no question.  So, to "declare" a string s, first use it as a string.  s := "" should be sufficient.  Modify the program again:
  47.  
  48. procedure main()
  49.     s1 := "This is a string"
  50.     write(s1)
  51. #    s2[2] := s1
  52. #    write(s2)
  53.     s3 := "Oh, no, Mr. Bill!  "
  54.     s4 := s3 || s1
  55.     write(s4)
  56.     s3[2] := s1
  57.     write(s3)
  58.     s5 := ""  # new
  59.     s5 := s1  # new
  60.     write(s5)  # new
  61.     exit()
  62. end
  63.  
  64. you get
  65.  
  66. This is a string
  67. Oh, no, Mr. Bill!  This is a string
  68. OThis is a string, no, Mr. Bill!  
  69. This is a string
  70.  
  71. Does this help?  If not, copy it and continue working with it.
  72.  
  73. Charles Hethcoat
  74.  
  75.  
  76.